<template>
	<view class="">
		<jnavbar :title="'订单详情'"></jnavbar>
		<!--订单支付页面 单商品-->

		<!-- <view class="app page_container" v-bind:class="type == 2 ? 'top_no' : ''"> -->
		<block v-if="type == 0">
			<scroll-view class="page_container" scroll-y>
				<!-- 自提or快递 -->
				<view class="adress_div">
					<view class="tabs">
						<view v-if="sendtype != 'self'" @click="changetabs(0)" :class="[tabIndex == 0 ? 'active' : '']"><text>快递</text></view>
						<view v-if="sendtype != 'send'" :class="[tabIndex == 1 ? 'active' : '']" @click="changetabs(1)"><text>自提</text></view>
						<!-- <view v-if="sendtype != 'self'" :class="[tabIndex == 2 ? 'active' : '']" @click="changetabs(2)"><text>同城</text></view> -->
					</view>
					<view class="adresslist">
						<swiper :current="tabIndex" @change="changeTab" class="uni-swiper">
							<swiper-item v-if="sendtype != 'self'">
								<view class="address_info uni-flex-row uni-flex-title" @click="getAddress(address)">
									<view class="u-flex">
										<view class="icon_div"><text class="el-sc-dingwei iconfont"></text></view>
										<view class="uni-flex-column" v-if="address">
											<view class="add_name">
												<text>{{ address.consignee }}</text>
												<text>{{ address.iphone }}</text>
											</view>
											<text class="add_content">{{ address.address.replace(/,/g, '') }}</text>
										</view>
										<view class="use" v-else><text>选择地址</text></view>
									</view>

									<text class="el-sc-xiangyou iconfont"></text>
								</view>
							</swiper-item>
							<swiper-item v-if="sendtype != 'send'">
								<view class="address_info uni-flex-row uni-flex-title" @click="selectstore(commoditys)">
									<view class="u-flex">
										<view class="icon_div"><text class="el-sc-dingwei iconfont"></text></view>
										<view class="uni-flex-column">
											<text class="add_name">{{ selectstoredata.name }}</text>
											<text>{{ selectstoredata.district.replace(/ /g, '') }}{{ selectstoredata.address }}</text>
										</view>
									</view>

									<text class="el-sc-xiangyou iconfont"></text>
								</view>
							</swiper-item>
						</swiper>
					</view>
				</view>
				<u-form class="user_info uni-block-form uni-view uni-flex-column" v-if="is_all_store" :model="form" :label-width="180" ref="uForm">
					<u-form-item class="item" label="姓名"><u-input placeholder="请输入自提人姓名" v-model="form.consignee" /></u-form-item>
					<u-form-item class="item" label="手机号码"><u-input placeholder="请输入自提人手机号码" v-model="form.iphone" /></u-form-item>
				</u-form>
				<view class="goodinfo weizhi">
					<view class="uni-flex-row uni-flex-title">
						<vimage class="img_box" :src="commoditys.master" mode=""></vimage>

						<view class="uni-flex-row goods_content">
							<view class="uni-flex-column info_text name">
								<text class="u-main-color u-line-2">{{ commoditys.name }}</text>
								<text class="u-tips-color">{{ commoditys.pvs_value || '' }}</text>
							</view>
							<view class="uni-flex-column info_text price">
								<text>{{ commoditys.price }}</text>
								<text>x{{ commoditys.num }}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="good_box">
					<u-cell-group>
						<!-- <u-cell-item @click="opencoupon(commoditys, -1)" title="优惠券">
							<text slot="right-icon" class="coupontxt" v-if="commoditys.coupon && commoditys.coupon.id">-{{ commoditys.coupon.denomination }}</text>
							<text slot="right-icon" v-else>不使用优惠券</text>
						</u-cell-item> -->
						<u-cell-item hover-class="none" :arrow="false" title="商品金额">
							<text slot="right-icon">{{ (commoditys.price * commoditys.num)}}</text>
						</u-cell-item>
					<!-- 	<u-cell-item hover-class="none" :arrow="false" title="运费" :value="freightall"></u-cell-item>
						<u-cell-item hover-class="none" :arrow="false" title="优惠" :value="couponprice"></u-cell-item> -->
						<u-cell-item hover-class="none" :arrow="false" :title="'剩余' + integralBalance.integral_text">
							<text slot="right-icon">{{ UserInfo.integral }}</text>
							<text slot="right-icon" class="coupontxt" v-if="is_integral">-{{ integral }}</text>
						</u-cell-item>
						
					<!-- 	<block v-if="integralprice > 0">
							
							<u-cell-item hover-class="none" :arrow="false" :title="integralBalance.integral_text + '抵扣'" value="">
								<u-switch :size="40" slot="right-icon" v-model="is_integral"></u-switch>
							</u-cell-item>
							<u-cell-item hover-class="none" :arrow="false" title="抵扣金额" v-if="is_integral" :value="'-￥' + integralprice"></u-cell-item>
						</block> -->
						<u-cell-item hover-class="none" :arrow="false">
							<view slot="right-icon" class="">
								<text>所需积分</text>
								<text class="pay_price">{{ allprice }}积分</text>
							</view>
						</u-cell-item>
					</u-cell-group>
				</view>

				<view class="goodinfo weizhi">
					<text>备注</text>
					<u-input type="textarea" v-model="remake" placeholder="备注信息"></u-input>
				</view>
				<u-gap height="140"></u-gap>
			</scroll-view>
			<view class="footer u-flex u-row-between">
				<view class="allprice">
					<text>合计</text>
					<text class="pay_price">{{ allprice }}积分</text>
				</view>
				<view class="btns"><u-button shape="circle" size="medium" @click="createOrder()">立即支付</u-button></view>
			</view>
		</block>
		<!--订单完成页面-->
		<block v-else-if="type == 2">
			<view class="page_container" scroll-y>
				<view class="status_div">
					<text class="status_text">{{ orderdetail.statustext }}</text>
					<vimage imgtype="1" class="image" src="static/images/self.png" mode=""></vimage>
				</view>
				<!-- 自提订单 -->
				<block v-if="orderdetail.order_type == 2">
					<view class="adress_div">
						<view class="adresslist">
							<view class="address_info uni-flex-row uni-flex-title" @click="opmap">
								<view class="uni-flex-column">
									<view class="add_name">
										<text>{{ orderdetail.consignee }}</text>
										<text>{{ orderdetail.iphone }}</text>
									</view>
									<view>
										<text style="margin-right: 20rpx;color: #333333;">{{ orderdetail.store.name }}</text>
										<text>{{ orderdetail.store.district.replace(/,/g, '') }}{{orderdetail.store.address}}</text>
									</view>
								</view>
								<text class="el-sc-xiangyou iconfont"></text>
							</view>
						</view>
					</view>
				</block>
				<block v-else>
					<view class="adress_div">
						<view class="adresslist">
							<view class="address_info uni-flex-row ">
								<view class="uni-flex-column">
									<view class="add_name">
										<text>{{ orderdetail.consignee }}</text>
										<text>{{ orderdetail.iphone }}</text>
									</view>
									<view>
										<text class="el-sc-dingwei iconfont"></text>
										<text>{{ orderdetail.address ? orderdetail.address.replace(/,/g, '') : '' }}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
				<view class="goods_list">
					<text class="title">订单商品</text>
					<view class="goods_div">
						<view class="uni-flex-row">
							<view @click="topdetail(orderdetail.orderCommodity.commodity_id)"><vimage class="img_box" :src="orderdetail.orderCommodity.master" mode=""></vimage></view>
							<view class="goods_content uni-flex-column">
								<text class="u-main-color u-line-2">{{ orderdetail.orderCommodity.name }}</text>
								<text class="u-tips-color">{{ orderdetail.orderCommodity.pvs_value || '' }}</text>
								<text>数量:{{ orderdetail.orderCommodity.count }}</text>
							</view>
							<view class="goods_price uni-flex-column">
								<text>{{ orderdetail.orderCommodity.money }}积分</text>
								<text>{{ orderdetail.orderCommodity.status_text }}</text>
								<view class="goods_btns">
									<view class="btns" v-if="orderdetail.order_type==1&&orderdetail.orderCommodity.status == 3" @click="gologistics(orderdetail.orderCommodity)">查看物流</view>
								</view>
							</view>
						</view>
					</view>
					<view class="uni-flex-row uni-flex-title order_cell boldtext">
						<text>商品合计</text>
						<text>{{ orderdetail.money }}积分</text>
					</view>
					<!-- <view class="uni-flex-row uni-flex-title order_cell">
						<text>优惠券</text>
						<text>￥{{ orderdetail.discount }}</text>
					</view>
					<view class="uni-flex-row uni-flex-title order_cell">
						<text>积分抵扣</text>
						<text>￥{{ orderdetail.discount_amount }}</text>
					</view>
					<u-gap height="2" bg-color="#eee" margin-top="15" margin-bottom="15"></u-gap>
					<view class="uni-flex-row uni-flex-title order_cell">
						<text>运费</text>
						<text>￥{{ orderdetail.freight }}</text>
					</view> -->

					<!-- <view class="uni-flex-row uni-flex-title order_cell boldtext">
						<text>实付款</text>
						<text class="pay_price">￥{{ orderdetail.allprice }}</text>
					</view> -->
				</view>
				<view class="order_detial">
					<text class="title">订单信息</text>
					<view class="uni-flex-row uni-flex-title order_cell">
						<text>订单编号</text>
						<view>
							<text>{{ orderdetail.order_no }}</text>
							<text class="mid-font fuzhi" @click="uniCopy(orderdetail.order_no)">复制</text>
						</view>
					</view>
					<view class="uni-flex-row uni-flex-title order_cell">
						<text>订单创建时间</text>
						<text>{{ orderdetail.create_time }}</text>
					</view>
					<view class="uni-flex-row uni-flex-title order_cell"></view>
				</view>
			
				<view class="order_detial">
					<text class="title">备注</text>
					<view class="uni-flex-row uni-flex-title order_cell">
						<view>
							<text>{{ orderdetail.remake }}</text>
						</view>
					</view>
				</view>
				<u-gap height="140"></u-gap>
			</view>
			<view class="footer u-flex u-row-between">
				<view class="allprice">
					<text>合计：</text>
					<text class="pay_price">{{ orderdetail.money }}积分</text>
				</view>
				<view class="btns">

					<u-button size="mini" shape="circle" @click="confirmOrder()" v-if="orderdetail.status == 2&&orderdetail.order_type==1">
						确认收货
					</u-button>
					<u-button
						size="mini"
						shape="circle"
						@click="evaluateOrder()"
						v-if="orderdetail.state == 8 && tradeSetting.is_show_evaluate == 1 && orderdetail.is_evaluate == 0"
					>
						订单评价
					</u-button>
					<u-button size="mini" shape="circle" @click="buildqrcode" v-if="orderdetail.status == 2 && orderdetail.order_type == 2">核销订单</u-button>
				</view>
			</view>
		</block>
		<!-- 核销二维码 -->
		<u-popup v-model="showPopupCenter" mode="center" border-radius="20">
			<view class="qrcodediv">
				<view class="qrcode_top u-flex u-row-between">
					<text>二维码</text>
					<text @click="showPopupCenter = false" class="el-sc-cuo11"></text>
				</view>
				<image :src="qrcode" mode=""></image>
				<!-- <image :src="qrcode" mode=""></image> -->
				<text>扫描二维码，核销商品</text>
				<u-button :custom-style="customStyle1" class="qrcode_btn" @click="saveimg(qrcode)">保存图片</u-button>
			</view>
		</u-popup>

	
		<uni-login ref="Login" @callback="logincallback"></uni-login>
		<bind-mobile @hide="hide" :bindshow="bindshow"></bind-mobile>
	</view>
</template>
<script>
import http from '@/common/http.js';
import base from '@/common/baseUrl';
import util from '@/common/util.js';
import {mapState, mapMutations} from 'vuex';

import store from '@/store';
export default {
	onShareAppMessage() {
		return this.wxShare();
	},
	data() {
		return {
			background: {
				backgroundColor: '#ff3c29'
			},
			bindshow: false,
			type: 0,
			showPopupBottom: false,
			showPopupCenter: false,
			//底层模态框
			popType: 'bottom',
			tabIndex: 0,
			qrcode: '',
			veriflist: [],
			clist: [],
			couponlist: [],
			availablelist: [],
			unavailablelist: [],
			select_id: -1,
			freightlist: [
				{
					freight: 0
				}
			],
			address: null,
			storelist: {},
			key: 0,
			merchantId: 0,
			selectstoredata: {
				name: '请选择门店',
				address: '',
				district: ''
			},
			is_store: false,
			is_integral: false,
			ordertype: 1,
			list: [
				{
					checked: false
				},
				{
					checked: false
				},
				{
					checked: false
				}
			],
			integralprice: 0,
			orderdetail: {
				orderCommodity:{
					
				}
			},
			form: {
				consignee: '',
				iphone: ''
			},
			sendtype: '',
			remake: '',
			tradeSetting: {},
			integralBalance: {},
			customStyle: {
				width: '690rpx'
			},
			customStyle1: {
				width: '300rpx',
				height: '82rpx',
				background: 'linear-gradient(90deg, #fe8e0a, #ff5011)',
				'box-shadow': '-2px 5px 9px 0px rgba(254, 140, 10, 0.5)',
				'border-radius': '41rpx',
				'font-size': '34rpx',
				color: '#ffffff'
			}
		};
	},
	onPullDownRefresh() {
		var _this = this;
		if (this.id) {
			this.judgeLogin(
				() => {
					_this.$store.commit('setlogin', false);
				},
				() => {
					_this.getdetail();
				}
			);
			// this.getdetail();
		} else {
			if (!_this.UserInfo.mobile && _this.mallBaseinfo && _this.mallBaseinfo.is_handset) {
				_this.bindshow = true;
			}
		}
	},
	async onLoad(e) {
		await this.$getWx
		this.getjuris(['tradeSetting', 'integralBalance']).then(a => {
			this.tradeSetting = a.tradeSetting;
			this.integralBalance = a.integralBalance;
		});
		// if (e.gid) {
		// 	this.getgood(e.gid);
		// }
		if(e.id){
			this.type=2;
			this.id=e.id
			this.getdetail()
		}
		// if (e.sendtype != 'self' && e.type != 4) {
		// 	this.getAddressList();
		// }
		// if (e.type == 1) {
		// 	//详情页进入
		// 	this.type = 0;
		// 	this.ordertype = 1;
		// 	this.sendtype = e.sendtype;
		// 	this.integraljudge();
		// } else if (e.type == 2) {
		// 	//购物车进入
		// 	this.type = 1;
		// 	this.ordertype = 2;
		// 	this.integraljudge();
		// 	this.sendtype = e.sendtype;
		// } else if (e.type == 3) {
		// 	//购物车进入（全部）
		// 	this.type = 1;
		// 	this.ordertype = 3;
		// 	this.integraljudge();
		// 	this.sendtype = e.sendtype;
		// } else if (e.type == 4) {
		// 	//订单详情
		// 	this.type = 2;
		// 	this.id = e.id;
		// }
	},
	onShow(e) {
		// #ifdef MP-WEIXIN
		let pages = getCurrentPages();
		let currPage = pages[pages.length - 1];
		if (currPage.data.address) {
			this.address = currPage.data.address;
			this.hasBuy = true;
		} else {
			this.address = null;
			this.hasBuy = false;
		}
		// #endif

		var _this = this;
		if (this.id) {
			this.judgeLogin(
				() => {
					_this.$store.commit('setlogin', false);
				},
				() => {
					_this.getdetail();
				}
			);
		} else {
			if (!_this.UserInfo.mobile && _this.mallBaseinfo && _this.mallBaseinfo.is_handset) {
				_this.bindshow = true;
			}
		}
	},

	watch: {
		address() {
			// this.shopCartFreight();
		}
	},
	computed: {
		is_all_store() {
			if (this.commoditys && this.commoditys.length > 0) {
				let list = this.commoditys.filter(a => {
					return a.is_store;
				});
				return list.length == this.commoditys.length;
			} else {
				return this.sendtype == 'self' || this.tabIndex == 1;
			}
		},

		freightall() {
			let freight = 0;
			if (this.commoditys && !Array.isArray(this.commoditys)) {
				if (this.tabIndex == 0) {
					freight = Number(this.freightlist[0].freight);
				}
			} else {
				this.freightlist.forEach((a, i) => {
					let c = this.commoditys.findIndex(_ => _.merchantId == a.merchantId);
					if (c > -1 && !this.commoditys[c].is_store) {
						freight = Number(a.freight) + freight;
					}
				});
			}
			return freight.toFixed(2);
		},
		goodsprice() {
			let goodsprice = 0;
			if (Array.isArray(this.commoditys)) {
				this.commoditys.forEach((a, i) => {
					a.list.forEach(c => {
						goodsprice = goodsprice + Number(c.price) * Number(c.num);
					});
				});
				return goodsprice
			}
		},
		couponprice() {
			if (this.commoditys && !Array.isArray(this.commoditys)) {
				let couponprice = this.commoditys.coupon.denomination ? this.commoditys.coupon.denomination : 0;
				return couponprice.toFixed(2);
			} else if (Array.isArray(this.commoditys)) {
				let couponprice = 0;
				this.commoditys.forEach(a => {
					couponprice = couponprice + (a.coupon.denomination ? a.coupon.denomination : 0);
				});
				return couponprice.toFixed(2);
			} else {
				return '';
			}
		},
		allprice() {
			let allprice = 0;
			if (this.commoditys && !Array.isArray(this.commoditys)) {
				allprice = Number(this.commoditys.price) * Number(this.commoditys.num) + Number(this.freightall) - Number(this.couponprice);
				if (this.is_integral) {
					allprice = allprice - Number(this.integralprice);
				}
				return allprice
			} else if (Array.isArray(this.commoditys)) {
				allprice = Number(this.goodsprice) + Number(this.freightall) - Number(this.couponprice);
				if (this.is_integral) {
					allprice = allprice - Number(this.integralprice);
				}
				return allprice
			} else {
				return '';
			}
		},
		// 计算发票
		invoiceStatus() {
			let stater = this.orderdetail.invoice ? this.orderdetail.invoice.status : -1;
			if (stater == 1) {
				return '发票正在审核中';
			} else if (stater == 2) {
				return '已开具发票';
			} else if (stater == 3) {
				return '发票审核失败';
			} else if (stater == -1) {
				return '本次不开具发票';
			}
		},
		...mapState({
			UserInfo: state => state.userInfo,
			commoditys: state => state.commoditys,
			mallBaseinfo: state => state.mallBaseinfo
		})
	},
	methods: {
		getgood(id) {
			this.$http('/integral/shop/goods/' + id, {}, 'GET').then(res => {});
		},
		init() {
			this.$refs.slist.afterload();
		},
		hide() {
			this.bindshow = false;
		},
		saveimg(path) {
			let url = util.getimgurl(path);
			// #ifdef MP-WEIXIN
			uni.downloadFile({
				url: url,
				success: res => {
					util.toSaveImage(res.tempFilePath);
				},
				fail() {
					uni.showToast({
						icon: 'none',
						title: '小程序码下载失败'
					});
				}
			});
			// #endif
			// #ifndef MP-WEIXIN
			util.toSaveImage(url);
			// #endif
		},
		logincallback(e) {
			if (e.islogin) {
				this.getdetail();
			} else {
				this.Jumpurl({
					type: 1,
					link: '../index/index',
					login_type: 1
				});
			}
		},
		//计算积分抵扣
		integraljudge() {
			let commodity = [];
			let Coupon = [];
			if (this.type == 0) {
				commodity.push({
					commodityId: this.commoditys.commodityId,
					sku: this.commoditys.sku
				});
				Coupon.push(this.commoditys.coupon.id);
			} else if (this.type == 1) {
				this.commoditys.forEach(a => {
					Coupon.push(a.coupon.id);
					a.list.forEach(b => {
						commodity.push({
							commodityId: b.commodityId,
							sku: b.sku
						});
					});
				});
			}
			let data = {
				commodity: JSON.stringify(commodity),
				total_price: this.allprice
			};
			if (Coupon.length > 0) {
				data.Coupon = JSON.stringify(Coupon);
			}

			this.$http('/integral/judge', data, 'post').then(res => {
				this.integralprice = res.data.msg.money;
				this.integral = Number(res.data.msg.integral);
				this.userCenter();
			});
		},
		/*优惠券*/
		//获取可用优惠券--购物车
		getcoupons() {
			let param = {};
			let list = this.commoditys;
			list.forEach(a => {
				param[a.merchantId] = [];
				a.list.forEach(b => {
					param[a.merchantId].push({
						commodity: b.commodityId,
						count: b.num,
						sku: b.sku
					});
				});
			});
			let data = {
				data: JSON.stringify(param)
			};
			http('/user/coupon/commodity', data, 'POST').then(res => {
				if (res.statusCode == 200) {
					this.coupondata = res.data.msg;
					if (this.coupondata.length > 0) {
						this.couponpice();
					}
				}
			});
		},
		//获取可用优惠券--单商品
		getcoupon() {
			let param = {};

			param[this.commoditys.merchantId] = [
				{
					commodity: this.commoditys.commodityId,
					count: this.commoditys.num,
					sku: this.commoditys.sku
				}
			];
			let data = {
				data: JSON.stringify(param)
			};
			http('/user/coupon/commodity', data, 'POST').then(res => {
				if (res.statusCode == 200) {
					this.coupondata = res.data.msg;
					if (this.coupondata.length > 0) {
						this.couponpice();
					}
				}
			});
		},
		//预选优惠券
		couponpice() {
			if (!Array.isArray(this.commoditys)) {
				let merchantId = this.commoditys.merchantId;
				let list = this.coupondata[merchantId].available;
				list = list.sort(this.sortNumber);
				this.commoditys.coupon = list[0].coupon;
			} else if (Array.isArray(this.commoditys)) {
				this.commoditys.forEach(a => {
					let merchantId = a.merchantId;
					let list = this.coupondata[merchantId].available;
					list = list.sort(this.sortNumber);
					a.coupon = list[0].coupon;
				});
			}
		},
		//排序
		sortNumber(a, b) {
			return b.coupon.denomination - a.coupon.denomination;
		},
		//选择优惠券弹窗
		opencoupon(commoditys, i) {
			this.select_id = i;

			let unavailablelist = this.coupondata[commoditys.merchantId].unavailable;
			let availablelist = this.coupondata[commoditys.merchantId].available;
			availablelist.forEach(a => {
				if (a.coupon.id == commoditys.coupon.id) {
					a.checked = true;
				} else {
					a.checked = false;
				}
			});
			this.availablelist = availablelist;
			this.unavailablelist = unavailablelist;
			this.$refs.conpon.open();
		},
		selectcoupon(item) {
			if (this.type == 0) {
				this.commoditys.coupon = item.coupon;
				this.commoditys.coupon_id = item.id;
			} else {
				this.commoditys[this.select_id].coupon = item.coupon;
				this.commoditys[this.select_id].coupon_id = item.id;
			}
			this.integraljudge();
			this.$refs.conpon.close();
		},
		/*优惠券end*/

		/*核销*/
		//获取核销二维码
		buildqrcode() {		
			http('/integral/shop/order/qrcode/'+this.id, {}, 'GET').then(res => {
				if (res.statusCode == 200) {
					let qrcode = base.imgUrl + res.data.msg;
					this.qrcode = qrcode;
					this.showPopupCenter = true;
					// this.$refs.popup.close()
					// this.$refs.codepopup.open();
				}
			});
		},
		//核销弹窗
		showpup() {
			// let data = {
			// 	order: this.id
			// };
			// http('integral/shop/order/qrcode/'+this.id, data, 'GET').then(res => {
			// 	if (res.statusCode) {
			// 		let veriflist = res.data.msg;
			// 		veriflist.forEach(a => {
			// 			if (a.status == 2) {
			// 				a.checked = true;
			// 			} else {
			// 				a.checked = false;
			// 			}
			// 		});
			// 		this.veriflist = veriflist;
			// 	}
			// 	this.$refs.popup.open();
			// });
		},
		/*核销end*/
		/*链接跳转*/
		//退款单详情
		toafterorder(id) {
			uni.navigateTo({
				url: 'aftersale_detail?id=' + id
			});
		},
		//申请售后
		aftersale(i) {
			uni.navigateTo({
				url: 'aftersale?id=' + i + '&oid=' + this.id
			});
		},
		//快递
		gologistics(item) {
			uni.navigateTo({
				url: 'logistics?id=' + item.logistics_no + '&address=' + this.orderdetail.address
			});
		},
		//获取地址页
		getAddress(obj) {
			if (obj) {
				uni.navigateTo({
					url: '/pages/mine/address/index?addressId=' + obj.id
				});
			} else {
				uni.navigateTo({
					url: '/pages/mine/address/index?addressId=' + 0
				});
			}
		},
		/*链接跳转end*/
		//总价计算
		getallprice() {},

		/*地址*/
		//获得地址列表
		getAddressList() {
			http('/order/userAddressList', {}, 'GET').then(
				res => {
					const json = res.data.msg;
					let list = json.data;

					//判断地址列表是否为空
					if (list.length > 0) {
						let data = list.filter(_ => {
							return _.type == 2;
						});
						if (data.length == 1) {
							this.address = data[0];
						}
					} else {
					}
				},
				e => {
					uni.showModal({
						title: '提示',
						content: e,
						showCancel: false
					});
					uni.hideLoading();
				}
			);
		},
		//运费计算
		shopCartFreight() {
			let commoditys = [];
			let payable = true;
			let nendsend = false;
			if (this.type == 0) {
				commoditys = this.commoditys;

				if (this.tabIndex == 0) {
					if (!this.address) {
						uni.showToast({
							title: '请选择收获地址',
							icon: 'none'
						});
						return false;
					}
				} else {
					if (!this.selectstoredata) {
						uni.showToast({
							title: '请选择门店',
							icon: 'none'
						});
						return false;
					} else {
						if(this.selectstoredata.id){
							commoditys.store_id = this.selectstoredata.id;
						}
						
					}
				}
			} else {
				this.commoditys.forEach(a => {
					a.list.forEach(b => {
						commoditys.push({
							id: b.commodityId,
							sku: b.sku,
							num: b.num,
							type: a.is_store ? 2 : 1,
							store_id: a.store_id
						});
					});
				});
			}

			let data = {
				type: this.ordertype,
				commoditys: JSON.stringify(commoditys),
				user_address_id: this.address.id
			};
			if (this.tabIndex == 0) {
				http('/order/shopCartFreight', data, 'POST').then(res => {
					if (res.statusCode == 200) {
						let list = res.data.msg;
						this.freightlist = list;
					} else {
						uni.showToast({
							title: res.data.msg
						});
					}
				});
			} else if (this.tabIndex == 2) {
				http('/Distribution/store', data, 'POST').then(res => {
					if (res.statusCode == 200) {
						let list = res.data.msg;
						this.freightlist = list;
					} else {
						uni.showToast({
							title: res.data.msg
						});
					}
				});
			}
		},
		//选择门店
		selectstore(item) {
			if (this.storelist[item.merchantId] && this.storelist[item.merchantId].length > 0) {
				uni.navigateTo({
					url: '/pages/mine/storelist/storelist?id=' + item.merchantId
				});
			} else {
				let data = {
					merchant_id: item.merchantId
				};
				http('/merchant/store/list?page=1&size=100', data, 'POST').then(res => {
					if (res.statusCode == 200) {
						let list = res.data.msg.data;
						if (list.length > 0) {
							this.storelist[item.merchantId] = list;
							uni.setStorageSync('storelist', JSON.stringify(this.storelist));
							uni.navigateTo({
								url: '/pages/mine/storelist/storelist?id=' + item.merchantId
							});
						}
					}
				});
			}
		},
		// 门店选择返回
		Editcart(item, id) {
			if (this.type != 1) {
				return false;
			}
			this.commoditys.forEach(a => {
				if (a.merchantId == id) {
					a.name = item.name;
					a.store_id = item.id;
				}
			});
		},
		//
		opmap() {
			let latitude = this.orderdetail.store.latitude;
			let longitude = this.orderdetail.store.longitude;
			uni.openLocation({
				latitude: latitude,
				longitude: longitude,
				success: function() {}
			});
		},
		//新建订单
		createOrder() {
			let coupons = [];
			let commoditys = [];
			let payable = true;
			let nendsend = false;
			if (!this.UserInfo.mobile && this.mallBaseinfo.is_handset) {
				this.bindshow = true;
				return false;
			}
			commoditys = this.commoditys;
			if (this.tabIndex == 0) {
				if (!this.address) {
					uni.showToast({
						title: '请选择收货地址',
						icon: 'none'
					});
					return false;
				}
				commoditys.type = 1;
				delete commoditys.store_id;
			} else {
				if (!this.selectstoredata) {
					uni.showToast({
						title: '请选择门店',
						icon: 'none'
					});
					return false;
				} else {
					commoditys.type = 2;
					commoditys.store_id = this.selectstoredata.id;
				}
			}

			let data = {
				id:this.commoditys.commodityId,
				
				number:this.commoditys.num,
				
				// type: this.ordertype,
				// commoditys: JSON.stringify(commoditys)
			};
			if(this.commoditys.sku){
				data.sku_id=this.commoditys.sku
			}
			if(commoditys.store_id){
				data.store_id=commoditys.store_id
			}
			if (!this.is_all_store) {
				if (this.address) {
					data.user_address_id = this.address.id;
				} else {
					uni.showToast({
						title: '请选择收获地址',
						icon: 'none'
					});
					return false;
				}
			} else {
				data.consignee = this.form.consignee;
				data.iphone = this.form.iphone;

				if (!data.consignee) {
					uni.showToast({
						title: '请填写自提人姓名',
						icon: 'none'
					});
					return false;
				}
				if (!this.$u.test.mobile(data.iphone)) {
					uni.showToast({
						title: '请填写正确的自提人手机号',
						icon: 'none'
					});
					return false;
				}
			}
			data.remake = this.remake;
			http('/integral/shop/order/create', data, 'POST').then(res => {
				if (res.statusCode == 200) {
					store.commit('setCommoditys', null);
					if (this.is_integral) {
						this.userCenter();
					}
					let data = res.data.msg;
					this.orderpay(data.id)					
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
				}
			});
		},
		orderpay(id){
			this.$http('/integral/shop/order/pay/'+id,{},'POST').then(res=>{
				this.id=id
				this.type=2
				this.getdetail()
			})
		},
		userCenter() {
			let params = {};
			this.$http('/user/UserCenter', params, 'GET').then(res => {
				let centerinfo = res.data.msg;
				let myUserInfo = Object.assign({}, this.UserInfo, centerinfo);
				this.$store.commit('setUserInfo', myUserInfo);
			});
		},
		//前往支付
		topay() {
			let list = [];
			list.push(this.orderdetail.order_no);
			list = list.join(',');
			let money = this.orderdetail.money;

			uni.navigateTo({
				url: 'pay?total=' + money + '&list=' + list
			});
		},
		//订单详情
		getdetail() {
			http('/integral/shop/order/' + this.id, {}, 'GET').then(res => {
				uni.stopPullDownRefresh();
				if (res.statusCode == 200) {
					let orderdetail = res.data.msg;
					// let freight = orderdetail.freight || 0;
					// orderdetail.freight = freight.toFixed(2);
					let allprice = Number(orderdetail.money) - Number(orderdetail.discount) - Number(orderdetail.discount_amount) + Number(orderdetail.freight);
					orderdetail.allprice = allprice.toFixed(2);
					orderdetail.statustext = util.getstatustext(orderdetail.status, orderdetail.order_type,3);

					this.orderdetail = orderdetail;
				} else {
					uni.showToast({
						title: res.data.error_msg,
						icon: 'none'
					});
				}
			});
		},
		//bf_orderconfirm
		bf_orderconfirm() {
			let list = this.orderdetail.orderCommodity;
			let _temp = [];
			let clist = [];
			list.forEach(e => {
				if (e.logistics_no && _temp.findIndex(_ => _.logistics_no == e.logistics_no) == -1) {
					_temp.push({
						express_company: e.express_company,
						logistics_no: e.logistics_no
					});
				}
			});

			//重构包裹清单
			if (_temp.length > 0) {
				_temp.forEach((e, i) => {
					let alist = list.filter(_ => _.logistics_no == e.logistics_no);
					let b = alist.filter(_ => {
						return _.after_status != '3' && _.after_status != '4';
					});
					let c = alist.filter(_ => _.status == 3);
					// let b = alist.filter(_ => _.after_status != '3');
					// if(b.length==alist.length)
					// let disabled=b>-1
					clist.push({
						name: '包裹' + (i + 1),
						orderCommodity: alist,
						checked: !(b.length == alist.length) && !(c.length == 0),
						disabled: !!(c.length == 0),
						status: !!(b.length == alist.length)
					});
				});
			}
			this.clist = clist;
			this.$refs.orderconfirm.open();
		},
		//确认收货
		confirmOrder() {
			var _this = this;
			// this.$refs.orderconfirm.close();
			uni.showModal({
				title: '是否确认收货',
				success(res) {
					if (res.confirm) {
					
						http('/integral/shop/order/receiving/'+_this.id, {}, 'POST').then(res => {
							if (res.statusCode == 200) {
								_this.getdetail();
							} else {
								uni.showToast({
									title: res.data.msg
								});
							}
						});
					}
				}
			});
		},
		//订单评价
		evaluateOrder() {
			uni.navigateTo({
				url: 'evaluate?id=' + this.id
			});
		},
		changecheck(item) {
			item.checked = !item.checked;
		},
		uniCopy(text) {
			util.uniCopy({
				content: text,
				success: res => {
					uni.showToast({
						title: res,
						icon: 'none'
					});
				},
				error: e => {
					uni.showToast({
						title: e,
						icon: 'none',
						duration: 3000
					});
				}
			});
		},
		//切换
		changePopup(e) {
			this.showPopupBottom = e.show;
		},
		changetabs(tabid) {
			if (this.sendtype == 'self') return;
			this.tabIndex = tabid;
		},

		changeTab(e) {
			let index = e.detail.current;
			this.tabIndex = index;
		},
		// 开具发票
		todetail() {
			if (this.orderdetail.invoice) {
				if (this.orderdetail.invoice.status == 2 || this.orderdetail.invoice.status == 1) {
					return false;
				}
			}
			uni.navigateTo({
				url: '../../pages/mine/invoice/detail?id=' + this.id
			});
		},
		topdetail(id) {
			this.Jumpurl({
				type: 1,
				link:'../goods/detail?id='+id
			});
		}
	}
};
</script>

<style lang="scss">
.order_container {
	height: calc(100vh - 90rpx);
	height: -webkit-calc(100vh - 90rpx);
}

.status_text {
	font-size: 48rpx;
	font-weight: bold;
}

.app {
	padding-top: 0rpx;

	&.top_no {
		padding-top: 0;
	}
}

.banner {
	background: #ff3c29;
	width: 750rpx;
	height: 160rpx;
	position: absolute;
	top: 0;
	z-index: 1;
}

.adress_div {
	width: 750rpx;
	background-color: #fff;
	position: relative;
	z-index: 2;
	border-radius: 12rpx;
	background: #f4f4f4;

	.addressline {
		width: 702rpx;
	}

	.item {
		padding: 15rpx 0rpx;
		margin: 0 20rpx;

		.label {
			width: 120rpx;
			font-size: 30rpx;
		}

		input {
			font-size: 24rpx;
			margin-left: 20rpx;
		}
	}

	.tabs {
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #f5f5f5;
		width: 750rpx;
		height: 88rpx;
		background: #ffffff;

		.active {
			color: #e5582b;

			text {
				border-bottom: 4rpx solid #e5582b;
			}
		}

		view {
			flex: 1;
			text-align: center;
			font-size: 30rpx;
			font-weight: 500;

			text {
				padding: 0 65rpx;
				line-height: 80rpx;
				display: inline-block;
				border-bottom: 4rpx solid #ffffff;
			}
		}
	}

	.adresslist {
		width: 710rpx;
		margin: 0 auto;
		height: 178rpx;
		margin-top: 20rpx;

		.uni-swiper {
			height: 178rpx;
			border-radius: 16rpx;
			position: relative;
			background: #ffffff;
		}
	}

	.address_info {
		font-size: 30rpx;
		color: #969696;
		padding: 0 24rpx;
		height: 178rpx;
		background: #ffffff;
		border-radius: 16rpx;

		.add_name {
			margin-bottom: 20rpx;

			text:first-child {
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
				margin-right: 18rpx;
			}
		}

		.el-sc-dingwei {
			// margin-right: 20rpx;
			font-size: 34rpx;
			color: #333333;
			margin-right: 10rpx;
		}

		.icon_div {
			width: 66rpx;
			height: 66rpx;
			background: linear-gradient(-90deg, #e4552a, #f0943f);
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 27rpx;

			.el-sc-dingwei {
				// margin-right: 20rpx;
				font-size: 34rpx;
				color: #ffffff;
			}
		}
	}

	.line {
		width: 100%;
		height: 1rpx !important;
		background-color: #f5f5f5;
	}
}

.user_info {
	background: #ffffff;
	width: 710rpx;
	margin: 20rpx auto;
	padding: 0 24rpx;
	border-radius: 16rpx;
}

.list {
	.item {
		font-size: 30rpx;
		color: #333;
		border-bottom: 1rpx solid #f5f5f5;
		padding: 20rpx 0;
		margin-bottom: 20rpx;

		/deep/.img_box {
			width: 140rpx;
			height: 140rpx;
			border-radius: 8rpx;
			margin-right: 10rpx;
		}

		.info_text {
			flex: 1;
			font-size: 28rpx;
			justify-content: space-between;
			height: 140rpx;
			padding-left: 20rpx;
			align-items: flex-start;

			.sm-font {
				color: #888;
				font-size: 24rpx;
			}
		}

		.iconfont {
			font-size: 40rpx;
		}

		.active {
			.iconfont {
				color: #ff3c29;
			}
		}
	}
}

.merchantName {
	width: 702rpx;
	background-color: #fff;
	font-size: 30rpx;
	padding: 20rpx;
	border-bottom: 1rpx solid #f5f5f5;
}

.good_box {
	width: 702rpx;
	margin: 10rpx auto;
	position: relative;
	z-index: 2;
	background-color: #fff;
	border-radius: 12rpx;
	overflow: hidden;

	/deep/.u-cell {
		padding: 16rpx 20rpx;
	}

	.item {
		padding: 10rpx 20rpx;
	}

	.fuzhi {
		text-decoration: underline;
		margin-left: 15rpx;
		color: #ff3c29;
	}

	font-size: 30rpx;
}

.goodinfo {
	position: relative;
	z-index: 2;
	width: 702rpx;
	background-color: #fff;
	// margin: 0rpx 32rpx;
	padding: 20rpx;
	font-size: 30rpx;
	border-bottom: 1rpx solid #f5f5f5;
	border-radius: 16rpx;

	.img_box {
		width: 180rpx;
		height: 180rpx;
		border-radius: 6rpx;
	}

	.goods_content {
		height: 180rpx;
		flex: 1;
		padding-left: 20rpx;
	}

	.info_text {
		height: 180rpx;
		font-size: 28rpx;

		// justify-content: space-between;
		&.name {
			flex: 1;
		}

		.u-line-2 {
			// height: 80rpx;
			line-height: 1.2;
		}

		text:nth-child(2) {
			margin-top: 10rpx;
			margin-left: 8rpx;
		}

		.status {
		}

		&.price {
			margin-left: 30rpx;
			align-items: flex-end;

			text:first-child {
				font-size: 28rpx;
				font-weight: 500;
				color: #333333;
				// line-height: 34px;
			}

			text:last-child {
				font-size: 26rpx;
				font-weight: 500;
				color: #999999;
			}
		}

		.sm-font {
			color: #888;
			font-size: 24rpx;
			// margin-top: 18rpx;
		}
	}

	.item {
		padding: 20rpx 0 0 0;
	}

	.evanswitch {
		transform: scale(0.6);
	}
}

.btns {
	font-size: 24rpx;
	padding: 10rpx 0rpx;

	button {
		margin-left: 10rpx;
		background: #fff;
		color: #ff3c29;
	}
}

.goods_list {
	width: 710rpx;
	background-color: #fff;
	margin: 20rpx auto;
	border-radius: 16rpx;
	padding: 40rpx 30rpx 10rpx 30rpx;

	.title {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
	}

	.goods_div {
		position: relative;
		z-index: 2;
		padding: 30rpx 0;
		font-size: 30rpx;
		border-bottom: 1rpx solid #f5f5f5;

		/deep/.img_box {
			width: 140rpx;
			height: 140rpx;
			border-radius: 8rpx;
		}

		.goods_content {
			width: 320rpx;
			height: 140rpx;
			justify-content: space-between;
			margin-left: 20rpx;

			text:first-child {
				font-size: 26rpx;
				color: #333333;
			}

			text:nth-child(2) {
				font-size: 20rpx;
			}

			text:last-child {
				font-size: 26rpx;
				color: #999999;
				font-weight: bold;
			}
		}

		.goods_price {
			flex: 1;
			align-items: flex-end;
			// justify-content: space-between;
			height: 140rpx;

			text:first-child {
				font-size: 26rpx;
				font-weight: bold;
				color: #333333;
			}

			text:nth-child(2) {
				font-size: 24rpx;
				font-weight: 500;
				color: #e4572b;
				margin-top: 10rpx;
			}

			.btns {
				background: #ffffff;
				border: 1rpx solid #e4572b;
				border-radius: 25rpx;
				font-size: 24rpx;
				font-weight: 500;
				color: #e4572b;
				padding: 6rpx 12rpx;
				text-align: center;
				margin-left: 15rpx;
			}
		}

		.goods_btns {
			position: absolute;
			right: 0;
			display: flex;
			width: 100%;
			bottom: 30rpx;
			justify-content: flex-end;
		}
	}
}

.order_detial {
	width: 710rpx;
	background-color: #fff;
	margin: 20rpx auto;
	border-radius: 16rpx;
	padding: 40rpx 30rpx;

	.title {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		display: block;
		margin-bottom: 15rpx;
	}
}

.order_cell {
	padding: 15rpx 0;
	color: #999999;

	&.boldtext {
		color: #333333;
		font-weight: bold;
	}

	.fuzhi {
		text-decoration: underline;
		margin-left: 15rpx;
		color: #ff3c29;
	}
}

.footer {
	// padding: 20rpx;
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	background: #fff;
	font-size: 30rpx;
	z-index: 20;
	padding: 0 32rpx;
	min-height: 70rpx;

	.allprice {
		text:first-child {
			// font-size: 36rpx;
		}
	}

	button {
		width: 161rpx;
		height: 54rpx;
		background: linear-gradient(-90deg, #e4552a, #f0943f);
		border-radius: 27rpx;
		color: #fff !important;
	}
}

.pay_price {
	color: #ff3c29;
	font-weight: 700;
	margin-left: 10rpx;
}

.weizhi {
	margin: 10rpx auto;
}

.mt_5 {
	margin-top: 10rpx;
}

.qrcodediv {
	width: 551rpx;
	height: 627rpx;
	background: #ffffff;

	background: #fff;
	padding-top: 20rpx;
	display: flex;
	flex-direction: column;
	align-items: center;

	.qrcode_top {
		width: 100%;
		padding: 0 20rpx;
		font-size: 32rpx;

		.el-sc-cuo11 {
			font-size: 36rpx;
		}
	}

	image {
		margin-top: 40rpx;
		width: 280rpx;
		height: 280rpx;
	}

	> text {
		text-align: center;
		margin-top: 20rpx;
		font-size: 34rpx;
		color: #999999;
	}

	.qrcode_btn {
		// width: 300rpx;
		// height: 82rpx;
		// background: linear-gradient(90deg, #fe8e0a, #ff5011);
		// box-shadow: -2px 5px 9px 0px rgba(254, 140, 10, 0.5);
		// border-radius: 41rpx;
		// font-size: 34rpx;
		// color: #ffffff;
		margin-top: 54rpx;
	}
}

/* 弹窗优惠券 */

.couponlist {
	height: 50vh;

	.item {
		background: #fde2e2;
		height: 160rpx;
		border-radius: 12rpx;
		margin-bottom: 20rpx;

		.price {
			width: 160rpx;
			height: 160rpx;
			justify-content: center;
			background: #ff3c29;
			color: #fff;
		}

		.content {
			width: 360rpx;
			padding-left: 20rpx;
			font-size: 24rpx;
			height: 80rpx;
			justify-content: space-between;
		}

		.btns {
			background-color: #ff3c29;
			color: #fff;
			width: 140rpx;
			font-size: 26rpx;
			text-align: center;
			padding: 10rpx 0;
			border-radius: 27rpx;
		}
	}

	.coupon_title {
		margin-bottom: 10rpx;
		display: block;
	}

	.unavailable {
		&.item {
			background: #f5f5f5;
		}

		.price {
			background: #808080;
		}
	}
}

.coupontxt {
	color: #ff3c29;
}

.nocoupon {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 100%;

	.btns {
		margin-top: 30rpx;
		background-color: #ff3c29;
		color: #fff;
		width: 280rpx;
		font-size: 26rpx;
		text-align: center;
		padding: 10rpx 0;
		border-radius: 27rpx;
	}
}

.orderconfirm {
	background-color: #fff;
	// width: 600rpx;
	border-radius: 12rpx;

	.active {
		color: #ff3c29;
	}

	.item {
		border: none;

		.info_text {
			width: 400rpx;

			.uni-flex-title {
				width: 100%;
			}
		}
	}

	.line {
		width: 536rpx;
		margin-left: 32rpx;
	}

	.uni-button {
		margin: 16rpx auto;
	}

	.check_div {
		display: flex;
		margin: 0 32rpx;
		padding: 16rpx 0;
		align-items: center;
		border-bottom: 1rpx solid #f5f5f5;

		view {
			margin-right: 16rpx;

			text {
				font-size: 40rpx;
			}
		}
	}
}

.store-ad {
	position: relative;
	align-items: center;
	display: flex;

	image {
		right: 0;
		top: 0;
		position: absolute;
		width: 80rpx;
		height: 80rpx;
		z-index: 1;
		background: #0077aa;
	}

	text {
		position: relative;
		z-index: 2;
	}

	// width: 80rpx;
	height: 80rpx;
}

.status_div {
	position: relative;
	// width: 750rpx;
	margin: 0 auto;
	// background: #ff3c29;
	// border-radius: 12rpx;
	width: 750rpx;
	height: 248rpx;
	background: linear-gradient(-90deg, #e4552a, #f0943f);

	color: #fff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	// padding: 16rpx 48rpx;
	padding: 0 55rpx;

	.image {
		width: 120rpx;
		height: 120rpx;
		margin-right: 24rpx;
	}

	// height:
}

.popup_div {
	height: 50vh;
}
.after_status {
	color: red;
	flex: 1;
	display: flex;
	align-items: self-start;
	height: 140rpx;
	font-size: 24rpx;
	/* text-align: right; */
	justify-content: flex-end;
}
</style>
